package com.ryder.ryderschool.controller;

import com.ryder.ryderschool.common.Result;
import com.ryder.ryderschool.entity.ProjectMember;
import com.ryder.ryderschool.service.ProjectMemberService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/projects/{projectId}/members")
@RequiredArgsConstructor
public class ProjectMemberController {

    private final ProjectMemberService projectMemberService;

    @PostMapping
    public Result<Void> addMember(
            @PathVariable Integer projectId,
            @RequestParam Integer userId,
            @RequestParam String role) {
        projectMemberService.addMember(projectId, userId, role);
        return Result.success();
    }

    @DeleteMapping("/{userId}")
    public Result<Void> removeMember(
            @PathVariable Integer projectId,
            @PathVariable Integer userId) {
        projectMemberService.removeMember(projectId, userId);
        return Result.success();
    }

    @PutMapping("/{userId}/role")
    public Result<Void> updateMemberRole(
            @PathVariable Integer projectId,
            @PathVariable Integer userId,
            @RequestParam String role) {
        projectMemberService.updateMemberRole(projectId, userId, role);
        return Result.success();
    }

    @GetMapping
    public Result<List<ProjectMember>> getProjectMembers(@PathVariable Integer projectId) {
        return Result.success(projectMemberService.getProjectMembers(projectId));
    }
} 